package test_new;

public class BubbleSort {
	int[] array;
	IntComparator comparator;
	SortMethod sorter;
	
//	public BubbleSort(int[] array){
//		this(array, new NaturalOrderComparator());
//	}
	
	public BubbleSort (int[] array, IntComparator comparator) {
		this.array = array;
		this.comparator = comparator;
	}
	
	public int[] getArray() {
		return array;
	}
	
//	public void doBubbleSort() {
//		sorter.sortArray();
//	}
//	
	public void makeBubbleSort() {
		for (int i=0; i<array.length-1; i++) {
			for (int j=i+1; j<array.length; j++ ) {
				if (isSwap(array[i], array[j])) {
					int temp = array[i];
					array[i] = array[j];
					array[j] = temp;
				}
			}
		}
	}
	
	protected boolean isSwap(int i, int j) {
		return comparator.compare(i, j) > 0;
	}

	

	public void revert() {
		for (int i = 0; i<array.length/2; i++) {
			int temp = array[i];
			array[i] = array[array.length-1-i];
			array[array.length-1-i] = temp;
		}
	}

}
